﻿using System;
using System.IO;
using UnityEngine;
/// <summary>
/// 全局设定
/// </summary>
public sealed class SFGlobalSetting
{
    #region platform 运行平台
    //https://docs.unity3d.com/Manual/PlatformDependentCompilation.html
    /// <summary>
    /// 运行平台
    /// </summary>
    static string mPlatform = string.Empty;
    /// <summary>
    /// 运行平台
    /// </summary>    
    public static string platform
    {
        get
        {
            if (string.IsNullOrEmpty(mPlatform))
            {
                mPlatform = "ab_";
                #region Platform Define
#if UNITY_STANDALONE_OSX
        //#define directive for compiling/executing code specifically for Mac OS X (including Universal, PPC and Intel architectures).
        mPlatform +="osx";
#elif UNITY_STANDALONE_WIN
                //#define directive for compiling/executing code specifically for Windows standalone applications.
                mPlatform += "win";
#elif UNITY_STANDALONE_LINUX
        //#define directive for compiling/executing code specifically for Linux standalone applications.
        mPlatform +="linux";
#elif UNITY_STANDALONE
        //#define directive for compiling/executing code for any standalone platform (Mac OS X, Windows or Linux).
        mPlatform +="standalone";
#elif UNITY_WII
        //#define directive for compiling/executing code for the Wii console.
        mPlatform +="wii";
#elif UNITY_IOS
        //#define directive for compiling/executing code for the iOS platform.
        mPlatform +="ios";
#elif UNITY_IPHONE
        //Deprecated. Use UNITY_IOS instead.
        mPlatform +="iphone";
#elif UNITY_ANDROID
        //#define directive for the Android platform.
        mPlatform +="android";
#elif UNITY_PS4
        //#define directive for running PlayStation 4 code.
        mPlatform +="ps4";
#elif UNITY_SAMSUNGTV
        //#define directive for executing Samsung TV code.
        mPlatform +="samsungtv";
#elif UNITY_XBOXONE
        //#define directive for executing Xbox One code.
        mPlatform +="xboxone";
#elif UNITY_TIZEN
        //#define directive for the Tizen platform.
        mPlatform +="tizen";
#elif UNITY_TVOS
        //#define directive for the Apple TV platform.
        mPlatform +="tvos";
#elif UNITY_WP_8_1
        //#define directive for Windows Phone 8.1.
        mPlatform +="wp_8_1";
#elif UNITY_WSA
        //#define directive for Windows Store Apps. Additionally, NETFX_CORE is defined when compiling C# files against .NET Core.
        mPlatform +="wsa";
#elif UNITY_WSA_8_1
        //#define directive for Windows Store Apps when targeting SDK 8.1.
        mPlatform +="wsa_8_1";
#elif UNITY_WSA_10_0
        //#define directive for Windows Store Apps when targeting Universal Windows 10 Apps. Additionally WINDOWS_UWP and NETFX_CORE are defined when compiling C# files against .NET Core.
        mPlatform +="wsa_10_0";
#elif UNITY_WINRT
        //Same as UNITY_WSA.
        mPlatform +="winrt";
#elif UNITY_WINRT_8_1
        //Equivalent to UNITY_WP_8_1 | UNITY_WSA_8_1. This is also defined when compiling against Universal SDK 8.1.
        mPlatform +="winrt_8_1";
#elif UNITY_WINRT_10_0
        //Equivalent to UNITY_WSA_10_0
        mPlatform +="winrt_10_0";
#elif UNITY_WEBGL
        //#define directive for WebGL.
        mPlatform +="webgl";
#elif UNITY_ADS
        //#define directive for calling Unity Ads methods from your game code. Version 5.2 and above.
        mPlatform +="ads";
#elif UNITY_ANALYTICS
        //#define directive for calling Unity Analytics methods from your game code. Version 5.2 and above.
        mPlatform +="analytics";
#elif UNITY_ASSERTIONS
        //#define directive for assertions control process.
        mPlatform +="assertions";
#endif
                #endregion
            }
            return mPlatform;
        }
    }
    #endregion

    #region persistentDataPath 持久数据路径
    /// <summary>
    /// 持久数据路径
    /// </summary>
    static string mPersistentDataPath = string.Empty;
    /// <summary>    
    /// 持久数据路径
    /// </summary>
    public static string persistentDataPath
    {
        get
        {
         
            if (string.IsNullOrEmpty(mPersistentDataPath))
            {
                mPersistentDataPath = Application.persistentDataPath;
            }

            return mPersistentDataPath;
        }
    }
    #endregion

    #region CNDDataPath 持久数据路径
    /// <summary>
    /// cdn持久数据路径
    /// </summary>
    static string mCDNDataPath = string.Empty;
    
    /// <summary>    
    /// CDN持久数据路径
    /// </summary>
    public static string cdnDataPath
    {
        get
        {
            if (mCDNDataPath == null)
            {
                Debug.LogError("===》》》 当前没有设置CDN Path！！！！！");
            }
            return mCDNDataPath;
        }set { mCDNDataPath = value; }
    }
    #endregion

    #region assetBundleRoot 资源包根路径
    /// <summary>
    /// 资源包根路径
    /// </summary>
    static string mAssetBundleRoot = string.Empty;
    /// <summary>
    /// 资源包根路径
    /// </summary>
    public static string assetBundleRoot
    {
        get
        {
            if (string.IsNullOrEmpty(mAssetBundleRoot))
            {
                mAssetBundleRoot = Path.Combine(persistentDataPath, platform);
            }
            return mAssetBundleRoot;
        }
    }
    #endregion
    #region cdnAssetBundleRoot 资源包根路径
    /// <summary>
    /// 资源包根路径
    /// </summary>
    static string mCdnAssetBundleRoot = string.Empty;
    /// <summary>
    /// 资源包根路径
    /// </summary>
    public static string cdnassetBundleRoot
    {
        get
        {
            if (string.IsNullOrEmpty(mCdnAssetBundleRoot))
            {
                mCdnAssetBundleRoot = cdnDataPath+ platform;
            }
            return mCdnAssetBundleRoot;
        }
    }
    #endregion 

    #region streamingAssetsRoot streamingAssets根目录
    /// <summary>
    /// streamingAssets根目录
    /// </summary>
    static string mStreamingAssetsRoot = string.Empty;

    /// <summary>
    /// streamingAssets根目录
    /// </summary>
    public static string streamingAssetsRoot
    {
        get
        {
#if UNITY_WEBGL
            if (string.IsNullOrEmpty(mStreamingAssetsRoot))
            {
                var uri = new System.Uri(Path.Combine(Application.streamingAssetsPath));
                mStreamingAssetsRoot= uri.ToString();
            }
           
#else
            if (string.IsNullOrEmpty(mStreamingAssetsRoot))
            {
               mStreamingAssetsRoot = Path.Combine(Application.streamingAssetsPath, platform);
            }
#endif
            return mStreamingAssetsRoot;
        }
    }
#endregion

    #region manifestStreamingAssetsRootPath Manifest文件StreamingAssetsRoot路径
    /// <summary>
    /// Manifest文件StreamingAssetsRoot路径
    /// </summary>
    static string mManifestStreamingAssetsRootPath = string.Empty;
    /// <summary>
    /// Manifest文件路径
    /// </summary>   
    public static string manifestStreamingAssetsRootPath
    {
        get {
            if (string.IsNullOrEmpty(mManifestStreamingAssetsRootPath))
            {
                mManifestStreamingAssetsRootPath = Path.Combine(streamingAssetsRoot, platform);
            }
            return mManifestStreamingAssetsRootPath;
        }
    }
    #endregion

    #region manifestAssetBundleRootPath Manifest文件AssetBundleRoot路径
    /// <summary>
    /// Manifest文件AssetBundleRoot路径
    /// </summary>
    static string mManifestAssetBundleRootPath = string.Empty;
    /// <summary>
    /// Manifest文件路径
    /// </summary>   
    public static string manifestAssetBundleRootPath
    {
        get
        {
            if (string.IsNullOrEmpty(mManifestAssetBundleRootPath))
            {
                mManifestAssetBundleRootPath = Path.Combine(assetBundleRoot, platform);
            }
            return mManifestAssetBundleRootPath;
        }
    }
    #endregion

    #region CDNmanifestAssetBundleRootPath Manifest文件AssetBundleRoot路径
    /// <summary>
    /// Manifest文件AssetBundleRoot路径
    /// </summary>
    static string mCdnManifestAssetBundleRootPath = string.Empty;
    /// <summary>
    /// Manifest文件路径
    /// </summary>   
    public static string cdnmanifestAssetBundleRootPath
    {
        get
        {
            if (string.IsNullOrEmpty(mCdnManifestAssetBundleRootPath))
            {
                mCdnManifestAssetBundleRootPath = Path.Combine(cdnassetBundleRoot, platform);
            }
            return mCdnManifestAssetBundleRootPath;
        }
    }
    #endregion


    #region manifestName Manifest文件名称
    /// <summary>
    /// Manifest文件名称
    /// </summary>   
    public readonly static string manifestName = typeof(AssetBundleManifest).Name;
    #endregion

    #region SubPackage Json 文件路径
    private static string m_PersistentSubPackage = string.Empty;
    /// <summary>
    ///  分包 信息路径
    /// </summary>
    public static string SubPacagePersistentFilePath
    {
        get {
            if (string.IsNullOrEmpty(m_PersistentSubPackage))
            {
                m_PersistentSubPackage = Path.Combine(SFGlobalSetting.assetBundleRoot, SubPackage);
            }
            return m_PersistentSubPackage;
        }
    }

    private static string m_StreamingAssetSubPackage = string.Empty;
    /// <summary>
    ///  分包 信息路径
    /// </summary>
    public static string SubPacageStreamingAssetFilePath
    {
        get
        {
            if (string.IsNullOrEmpty(m_StreamingAssetSubPackage))
            {
                m_StreamingAssetSubPackage = Path.Combine(SFGlobalSetting.streamingAssetsRoot, SubPackage);
            }
            return m_StreamingAssetSubPackage;
        }
    }

    public const string SubPackage = "subpackage.json";
   


    #endregion

    #region wwwPrefix WWW前缀
    /// <summary>
    /// WWW前缀
    /// </summary>
    public static string wwwPrefix
    {
        get
        {
            return
#if UNITY_WEBGL
string.Empty;
#else
 @"file:///";
#endif
        }
    }
    #endregion
}
